#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int head[N], a[N], b[N], rt;
int ver[N], Next[N], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int lc[N], rc[N], sz[N], sum[N], dis[N], root[N];
void init() { dis[0] = -1; }
void pushup(int x) {
  sz[x] = sz[lc[x]] + sz[rc[x]] + 1;
  sum[x] = sum[lc[x]] + sum[rc[x]] + a[x];
}
int merge(int x, int y) {
  if (!x || !y) return x + y;

  if (a[x] == a[y] ? x > y : a[x] < a[y]) swap(x, y);
  rc[x] = merge(rc[x], y);
  if (dis[lc[x]] < dis[rc[x]]) swap(lc[x], rc[x]);
  dis[x] = dis[rc[x]] + 1;

  pushup(x);
  return x;
}
ll ans = 0;
void dfs(int u) {
  if (a[u] <= m)
    root[u] = u, sz[u] = 1, sum[u] = a[u];
  else
    root[u] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    dfs(v);
    root[u] = merge(root[v], root[u]);
    while (sum[root[u]] > m) root[u] = merge(lc[root[u]], rc[root[u]]);
  }
  ans = max(ans, 1ll * b[u] * sz[root[u]]);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) {
    int fi;
    cin >> fi >> a[i] >> b[i];
    if (!fi)
      rt = i;
    else
      add(fi, i);
  }
  init();
  dfs(rt);
  cout << ans;
  return 0;
}